const md = require('../../utils/md5.js');
const app = getApp();
const post = require('../../utils/post.js');
Page({

  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    if (options.accid) {
      var datas = {};
      datas.where = "AccID = " + options.accid;
      var datacall = function (res) {
        console.log(res);
        if (res.data.data.length > 0) {
          var star = res.data.data[0].StarLevel;
          var data = res.data.data[0];
          if (data.Memo && data.Memo.length > 13) {
            data.Memo = data.Memo.substring(0, 12) + "...";
          }
          if (data.Brands && data.Brands.length > 13) {
            data.Brands = data.Brands.substring(0, 12) + "...";
          }
          if (data.ServiceArea && data.ServiceArea.length > 13) {
            data.ServiceArea = data.ServiceArea.substring(0, 12) + "...";
          }
          that.setData({
            depid:data.AccID,
            frinfo: data,
            star: star,
            starnone: 5 - star,
            frmebid: options.mebid,
            myid: wx.getStorageSync('mebid'),
            isfriend: options.isfriend,
            relid: options.relid,
          })
        }
      }
      var res2 = post.getdata("/BO/TR_Account/Query", datas, datacall);
    }
  },
  call: function () {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.frinfo.Tel,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  addfriend: function () {
    // 添加好友
    var that =this;
    var datas = {};
    var data = {};
    datas.MyMebID = that.data.myid;
    datas.FrMebID = that.data.frmebid;
    datas.DepID = that.data.depid;
    data.data = JSON.stringify(datas);
    console.log(datas);
    var datacall = function (res) {
      console.log(res);
      if (res.data.code == 0) {
        console.log(res.data.code)
        that.setData({
          isfriend:1
        })
        return;
      }
    }
    var res2 = post.getdata("/BO/BA_Friends/Add", data, datacall);
  },
  removefriend: function (e) {
    var that = this;
    // 添加好友
    var datas = {};
    datas.RelID = that.data.relid;
    console.log(datas);
    var datacall = function (res) {
      console.log(res);
      if (res.data.code == 0) {
        that.setData({
          isfriend:0
        })
        console.log(res.data.code)
        return;
      }
    }
    var res2 = post.getdata("/BO/BA_Friends/Delete", datas, datacall);
  },
  showshops: function () {
    wx.navigateTo({
      url: '/pages/shopdetail/shopdetail?id=' + this.data.frinfo.AccID+"&type=show",
    })
  }
})